﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;


namespace ImportPiket
{
    /// <summary>
    /// Логика взаимодействия для ImportPage1.xaml
    /// </summary>
    public partial class ImportPage1 : Page
    {
        /// <summary>
        /// Флаг - инициализация формы
        /// </summary>
        bool isInit;

        public ImportPage1()
        {
            isInit = false;
            InitializeComponent();
            isInit = true;
            textBoxFileName.Text = PrjProperty.fileName;
            comboBoxFileType.SelectedIndex = PrjProperty.typeFile;
            PrjProperty.txtData = "";
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            // Create OpenFileDialog
            var dlg = new Microsoft.Win32.OpenFileDialog() { DefaultExt = "*.*", Filter = "Любые файлы (*.*)|*.*" };

            // Display OpenFileDialog by calling ShowDialog method
            Nullable<bool> result = dlg.ShowDialog();

            // Get the selected file name and display in a TextBox
            if (result == true)
            {
                // Open document
                PrjProperty.fileName = dlg.FileName;
                textBoxFileName.Text = dlg.FileName;
            }  
        }

        private void ComboBoxFileTypeSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (isInit)
            {
                PrjProperty.typeFile = Convert.ToInt32(comboBoxFileType.SelectedIndex);
            }
        }

        private void TextBoxFileNameTextChanged(object sender, TextChangedEventArgs e)
        {
            if (isInit)
            {
                PrjProperty.fileName = textBoxFileName.Text;
            }
        }

      
    }
}
